package fr.mma.livraison;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import fr.mma.livraison.dao.AdminDao;

@SuppressWarnings("serial")
public class RedirectServlet extends HttpServlet {

	final static protected AdminDao dao = new AdminDao();

	public void doGet(final HttpServletRequest req, final HttpServletResponse resp) throws IOException {
		try {
			String redirect;
			if (req.getUserPrincipal() != null && dao.isAdmin(req.getUserPrincipal().getName())) {
				redirect = getServletConfig().getInitParameter("redirectAdmin");
			} else {
				redirect = getServletConfig().getInitParameter("redirect");
			}
			req.getRequestDispatcher(redirect).forward(req, resp);
			
		} catch (ServletException e) {
			e.printStackTrace();
		}

	}
}
